<?php
namespace Helper\Action;

class Action
{
	protected $classes = array();

	public function __construct()
	{
		$this->loadClass(dirname(__FILE__));
	}

	private function loadClass($dir)
	{
		$resource	= opendir($dir);
		while ($content	= readdir($resource))
		{
			if ($content == '.' || $content == '..' || $content == '.svn')
			{
				continue;
			}
			else if (is_file($dir.'/'.$content) && $content != 'Action.php')
			{
				$namespace	= explode('/Helper/Action', $dir);
				$namespace	= str_replace('/', '\\', $namespace[count($namespace)-1]);

				$content	= explode('.',$content);
				$class		= '\Helper\Action'.$namespace.'\\'.$content[0];
				$this->classes[]	= new $class();
			}
			else if (is_dir($dir.'/'.$content))
			{
				$this->loadClass($dir.'/'.$content);
			}

		}
		closedir($resource);
	}

	public function getClass($className)
	{
		foreach ($this->classes as $classe)
		{
			if ($classe instanceof $className)
				return $classe;
		}
	}
}